/*
 *  NoteInfo.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/12/05.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "NoteInfo.h"
#include "WellTemperament.h"
#include "NullWaveTable.h"
#include <sstream>

namespace sc {

	NoteInfo::NoteInfo()
		: frequency( 0.0 ),
		  duration( 0.0 ),
		  dynamics( 0.0 ),
		  dynamicsCurve( NullWaveTable::GetInstance() ),
		  phaseShift( 0.0 )
	{}
	
	NoteInfo::NoteInfo( const NoteInfo& info )
		: frequency( info.frequency ),
		  duration( info.duration ),
		  dynamics( info.dynamics ),
		  dynamicsCurve( info.dynamicsCurve ),
		  phaseShift( info.phaseShift )
	{}


	NoteInfo::NoteInfo( Note::MidiNumber number, double duration, double dynamics, double phaseShift )
		: frequency( WellTemperament::GetFrequency( number ) ),
		  duration( duration ),
		  dynamics( dynamics ),
		  dynamicsCurve( NullWaveTable::GetInstance() ),
		  phaseShift( phaseShift )
	{}

	NoteInfo::NoteInfo( double frequency, double duration, double dynamics, double phaseShift )
		: frequency( frequency ),
		  duration( duration ),
		  dynamics( dynamics ),
		  dynamicsCurve( NullWaveTable::GetInstance() ),
		  phaseShift( phaseShift )
	{}


	NoteInfo::NoteInfo( Note::MidiNumber number, double duration, double dynamics, const WaveTable& dynamicsCurve, double phaseShift )
		: frequency( WellTemperament::GetFrequency( number ) ),
		  duration( duration ),
		  dynamics( dynamics ),
  		  dynamicsCurve( & dynamicsCurve ),
		  phaseShift( phaseShift )
	{}

	NoteInfo::NoteInfo( double frequency, double duration, double dynamics, const WaveTable& dynamicsCurve, double phaseShift )
		: frequency( frequency ),
		  duration( duration ),
		  dynamics( dynamics ),
  		  dynamicsCurve( & dynamicsCurve ),
		  phaseShift( phaseShift )
	{}

	NoteInfo& NoteInfo::operator = ( const NoteInfo& info )
	{
		if ( this == & info )
		{
			return * this;
		}
		frequency = info.frequency;
		duration = info.duration;
		dynamics = info.dynamics;
		dynamicsCurve = info.dynamicsCurve;
		phaseShift = info.phaseShift;
		return * this;
	}

	std::string NoteInfo::ToString() const
	{
		std::stringstream ss;
		ss << "frequency: " << frequency << ", duration: " << duration << ", dynamics: " << dynamics << ", phaseShift: " << phaseShift;
		return ss.str();
	}

}
